package com.test.thread.example01;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * BlockingRejectedExecutionHandler
 */
public class BlockingRejectedExecutionHandler implements RejectedExecutionHandler {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        try {
            // 阻塞等待，直到有空闲线程或队列有空间
            executor.getQueue().put(r);
        } catch (InterruptedException e) {
            // 捕获中断异常
            Thread.currentThread().interrupt();
        }
    }
}
